package cn.lenchu.stock.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
 * @author lenchu
 */
@AllArgsConstructor
@Getter
public enum StandardCodeTypeEnum {

    /**
     * 沪市
     */
    SH("SH", "SH", "沪市"),
    SZ("SZ", "SZ", "深市"),
    HK("HK", "HK", "港市"),

    JJ("JJ", "JJ", "基金(场外)"),

    CSI("ICS", "CSI", "中证指数"),
    HKI("IHK", "HKI", "港市指数"),
    ;

    public static final String SUFFIX_SEPARATOR = ".";

    /**
     * prefix保证唯一
     */
    @Deprecated
    private final String prefix;

    /**
     * 拟弃用前缀, 改用后缀, 后缀与Code之间使用{@link StandardCodeTypeEnum#SUFFIX_SEPARATOR}分隔
     */
    private final String suffix;
    private final String desc;

    /**
     * 根据 Code 获取拼接好的 StandardCode
     * @param code Code
     * @return StandardCode
     */
    public String getStandardCode(@NonNull String code) {
        return code + SUFFIX_SEPARATOR + this.getSuffix();
    }

    public static StandardCodeTypeEnum getBySuffix(String suffix) {
        for (StandardCodeTypeEnum value : StandardCodeTypeEnum.values()) {
            if (value.suffix.equalsIgnoreCase(suffix)) {
                return value;
            }
        }
        return null;
    }

    @Deprecated
    public static StandardCodeTypeEnum getByPrefix(String prefix) {
        for (StandardCodeTypeEnum value : StandardCodeTypeEnum.values()) {
            if (value.prefix.equals(prefix)) {
                return value;
            }
        }
        return null;
    }
}
